home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / os2 / sysb091a.zip / sysbench / src / pmb_sieve.c < prev    next >
C/C++ Source or Header  |  1996-05-23  |  20KB  |  742 lines

  1. /****************** Start NSIEVE C Source Code ************************/
  2.  
  3. /****************************************************************/
  4. /*                          NSIEVE                              */
  5. /*                     C Program Source                         */
  6. /*          Sieve benchmark for variable sized arrays           */
  7. /*                Version 1.2b, 26 Sep 1992                     */
  8. /*             Al Aburto (aburto@marlin.nosc.mil)               */
  9. /*                      ('ala' on BIX)                          */
  10. /*                                                              */
  11. /*                                                              */
  12. /* This Sieve of Eratosthenes program works with variable size  */
  13. /* arrays. It is a straight forward extension of the original   */
  14. /* Gilbreath version ( Gilbreath, Jim. "A High-Level Language   */
  15. /* Benchmark." BYTE, September 1981, p. 180, and also Gilbreath,*/
  16. /* Jim and Gary. "Eratosthenes Revisited: Once More Through the */
  17. /* Sieve." BYTE January 1983, p. 283 ). Unlike the Sieve of     */
  18. /* Gilbreath, NSIEVE uses register long variables, pointers,and */
  19. /* large byte arrays via 'malloc()'.  Maximum array size is     */
  20. /* currently set at 2.56 MBytes but this can be increased or    */
  21. /* decreased by changing the program LIMIT constant.  NSIEVE    */
  22. /* provides error checking to ensure correct operation.  Timer  */
  23. /* routines are provided for several different systems. NSIEVE  */
  24. /* results won't generally agree with the Gilbreath Sieve       */
  25. /* results because NSIEVE specifically uses register long       */
  26. /* variables. NSIEVE, and Sieve, are programs designed          */
  27. /* specifically to generate and printout prime numbers (positive*/
  28. /* integers which have no other integral factor other than      */
  29. /* itself and unity, as 2,3,5,7,11, ... ). NSIEVE does not      */
  30. /* conduct the 'typical' instructions one might expect from the */
  31. /* mythical 'typical program'. NSIEVE results can be used to    */
  32. /* gain a perspective into the relative performance of different*/
  33. /* computer systems, but they can not be used in isolation to   */
  34. /* categorize the general performance capabilities of any       */
  35. /* computer system (no single benchmark program currently can do*/
  36. /* this).                                                       */
  37. /*                                                              */
  38. /* The program uses a maximum array size of 2.56 MBytes. You can*/
  39. /* increase or lower this value by changing the 'LIMIT' define  */
  40. /* from 9 to a higher or lower value.  Some systems (IBM PC's   */
  41. /* and clones) will be unable to work beyond 'LIMIT = 3' which  */
  42. /* corresponds to an array size of only 40,000 bytes. Be careful*/
  43. /* when specifying LIMIT > 3 for these systems as the system may*/
  44. /* crash or hang-up. Normally NSIEVE will stop program execution*/
  45. /* when 'malloc()' fails.                                       */
  46. /*                                                              */
  47. /* The maximum array size is given by:                          */
  48. /*              size = 5000 * ( 2 ** LIMIT ).                   */
  49. /*                                                              */
  50. /* The array 'Number_Of_Primes[LIMIT]' is intended to hold the  */
  51. /* correct number of primes found for each array size up to     */
  52. /* LIMIT = 20, but the array is only currently defined up to    */
  53. /* LIMIT = 13.                                                  */
  54. /*                                                              */
  55. /* Program outputs to check for correct operation:              */
  56. /*    Array Size  LIMIT    Primes Found      Last Prime         */
  57. /*     (Bytes)                                                  */
  58. /*         8191       0            1899           16381         */
  59. /*        10000       1            2261           19997         */
  60. /*        20000       2            4202           39989         */
  61. /*        40000       3            7836           79999         */
  62. /*        80000       4           14683          160001         */
  63. /*       160000       5           27607          319993         */
  64. /*       320000       6           52073          639997         */
  65. /*       640000       7           98609         1279997         */
  66. /*      1280000       8          187133         2559989         */
  67. /*      2560000       9          356243         5119997         */
  68. /*      5120000      10          679460        10239989         */
  69. /*     10240000      11         1299068        20479999         */
  70. /*     20480000      12         2488465        40960001         */
  71. /*     40960000      13         4774994        81919993         */
  72. /*     81920000      14         -------       ---------         */
  73. /****************************************************************/
  74.  
  75. /****************************************************/
  76. /* Example Compilation:                             */
  77. /* (1) UNIX Systems:                                */
  78. /*     cc -O -DUNIX nsieve.c -o nsieve              */
  79. /*     cc -DUNIX nsieve.c -o nsieve                 */
  80. /****************************************************/
  81.  
  82. #include <stdio.h>
  83. #ifndef vax
  84. #include <stdlib.h>
  85. #endif
  86. #include <math.h>
  87.              /***********************************************/
  88. #define LIMIT 8      /* You may need to change this to '3' for PC's */
  89.              /* and Clones or you can experiment with higher*/
  90.              /* values, but '13' is currently the max.      */
  91.              /***********************************************/
  92.  
  93. /***************************************************************/
  94. /* Timer options. You MUST uncomment one of the options below  */
  95. /* or compile, for example, with the '-DUNIX' option.          */
  96. /***************************************************************/
  97. /* #define Amiga       */
  98. /* #define UNIX        */
  99. /* #define UNIX_Old    */
  100. /* #define VMS         */
  101. /* #define BORLAND_C   */
  102. /* #define MSC         */
  103. /* #define MAC         */
  104. /* #define IPSC        */
  105. /* #define FORTRAN_SEC */
  106. /* #define GTODay      */
  107. /* #define CTimer      */
  108. /* #define UXPM        */
  109.  
  110. #ifdef Amiga
  111. #include <exec/types.h>
  112. #include <ctype.h>
  113. #endif
  114.  
  115. #ifdef BORLAND_C
  116. #include <ctype.h>
  117. #include <dos.h>
  118. #endif
  119.  
  120. #ifdef MSC
  121. #include <ctype.h>
  122. #endif
  123.  
  124. #ifndef TRUE
  125. #define TRUE 1
  126. #define FALSE 0
  127. #endif
  128.  
  129. #define INCL_DOSMISC
  130. #include <os2.h>
  131.  
  132. static double nulltime,runtime,TimeArray[4];
  133. static double reftime,adj_time,emips;
  134. static double hmips,lmips,smips[21];
  135.  
  136. static long L_Prime,N_Prime;      /* Last Prime and Number of Primes Found */
  137. static long ErrorFlag;
  138.  
  139. static long Number_Of_Primes[21]; /* List of Correct Number of Primes for */
  140.                /* each sieve array size.               */
  141.  
  142. static long NLoops[21];
  143.  
  144. static SIEVE(long m,long n,long p);
  145. int sieve_time(double* p);
  146. void err(char* s);
  147.  
  148. double pmb_sieve(void)
  149. {
  150.  
  151. long  i,j,k,p;
  152. double sumtime;
  153.  
  154. /*
  155. printf("\n   Sieve of Eratosthenes (Scaled to 10 Iterations)\n");
  156. printf("   Version 1.2b, 26 Sep 1992\n\n");
  157. printf("   Array Size   Number   Last Prime     Linear");
  158. printf("    RunTime    MIPS\n");
  159. printf("    (Bytes)   of Primes               Time(sec)");
  160. printf("    (Sec)\n");
  161. */
  162.     
  163.             /*******************************/
  164.             /* Number of        Array Size */
  165.             /* Primes Found      (Bytes)   */
  166. Number_Of_Primes[0] =     1899;      /*       8191 */
  167. Number_Of_Primes[1] =     2261;      /*      10000 */
  168. Number_Of_Primes[2] =     4202;      /*      20000 */
  169. Number_Of_Primes[3] =     7836;      /*      40000 */
  170. Number_Of_Primes[4] =    14683;      /*      80000 */
  171. Number_Of_Primes[5] =    27607;      /*     160000 */
  172. Number_Of_Primes[6] =    52073;      /*     320000 */
  173. Number_Of_Primes[7] =    98609;      /*     640000 */
  174. Number_Of_Primes[8] =   187133;      /*    1280000 */
  175. Number_Of_Primes[9] =   356243;      /*    2560000 */
  176. Number_Of_Primes[10]=   679460;      /*    5120000 */
  177. Number_Of_Primes[11]=  1299068;      /*   10240000 */
  178. Number_Of_Primes[12]=  2488465;      /*   20480000 */
  179. Number_Of_Prime